﻿using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite;

public class Skill
{
	private Timer skill_timer;
	public bool useful;
	private Skill_data data;
	private Character holder;

	public int ID;
	public float attack_distance;
	public float cd_time;
	public bool auto_use;

	public Skill(Character sk_holder,int id)
	{
		holder = sk_holder;
		ID = id;
		auto_use = true;
		attack_distance = 1.5f;
		cd_time = 1.0f;

		//data = new Skill_data(id);

		skill_timer = new Timer(cd_time);
        skill_timer.tick += delegate(){useful = true;};
        useful = true;
	}

	public Skill_effect Get_skill_effect(Damage dmg,Vector3 start_pos,Character hiter_sc, Character hited_sc)
    {
        GameObject obj = Gamecontrol.Instance.Get_skill_effect(ID);//根据id选择对应特效
        obj.transform.position = start_pos;
        Skill_effect skill_effect = obj.GetComponent<Skill_effect>();
        skill_effect.ini(dmg,hiter_sc, hited_sc);
        return skill_effect;
    }

	public Damage Hit(Character hited)
	{	
        skill_timer.Restart();
        useful = false;
		return Implement(hited);
	}

	private Damage Implement(Character hited)
	{
		//Debug.Log("对目标"+ hited.name + "造成了"+ data.direct_dmg +"点伤害");
		return new Damage(holder,hited,1);
	}
	public float Past_time()
    {
        return skill_timer.Past_time;
    }
	public void Update ()
	{
		skill_timer.Update(Time.deltaTime);
	}
}
